<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/4/8
  Time: 11:10
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html class="x-admin-sm">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.2</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/font.css">
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/xadmin.css">
    <script src="<%=request.getContextPath()%>/lib/layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="<%=request.getContextPath()%>/js/xadmin.js"></script>
</head>
<body>
<div class="x-nav">
          <span class="layui-breadcrumb">
            <a href="">首页</a>
            <a href="">演示</a>
            <a>
              <cite>导航元素</cite></a>
          </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i></a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <%--<div class="layui-card-header">
                    <button class="layui-btn layui-btn-danger" onclick="delAll()"><i class="layui-icon"></i>批量删除</button>
                    <button class="layui-btn" onclick="xadmin.open('添加权限','<%=request.getContextPath()%>/permission-add.jsp',800,600)"><i class="layui-icon"></i>添加</button>
                </div>--%>
                <div class="layui-card-body ">
                    <table class="layui-table" id="permission-table" lay-filter="permission-table-filter"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script type="text/html" id="toolbarDemo">
    <div class="layui-btn-container">
        <button class="layui-btn layui-btn-danger" lay-event="getCheckData">批量删除</button>
        <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">添加权限</button>
    </div>
</script>
<script>
    layui.use(['laydate','form','table'], function(){
        var laydate = layui.laydate;
        var form = layui.form;
        let table = layui.table;

        table.render({
            elem:"#permission-table",
            url:"/permission/queryAll",
            method:"get",
            toolbar: '#toolbarDemo',
            cols:[[
                {type:'checkbox'}
                ,{field:'id',  title: 'ID', sort: true}
                ,{field:'permissionName',  title: '权限名称'}
                ,{field:'url', title: '权限路径'}
            ]]
        })
        //头工具栏事件
        table.on('toolbar(permission-table-filter)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            let ids = [];
            switch(obj.event){
                case 'getCheckData':
                    var data = checkStatus.data;
                    $.each(data,function(index,permission){
                        ids.push(permission.id)
                    })
                    layer.confirm('确认要删除吗？'+ids,function(index){
                        //捉到所有被选中的，发异步进行删除
                        $.ajax({
                            url:"/permission/deletePermissions",
                            method:"post",
                            data:{"ids":ids},
                            //防止深度序列化
                            traditional: true
                        })
                        layer.msg('删除成功', {icon: 1});
                        $(".layui-form-checked").not('.header').parents('tr').remove();
                    });
                    break;
                case "getCheckLength":
                    xadmin.open('添加权限','<%=request.getContextPath()%>/permission-add.jsp',800,600);
                    break;
            };
        });
    });

</script>
</html>